<%@page import="java.util.List"%>
<%@page import="com.jfinal.plugin.activerecord.Page"%>
<%@page import="com.hongye.app.model.AuthorModel"%>
<%@page import="com.hongye.app.model.MenuModel"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8"%>
 <% AuthorModel auth = (AuthorModel)request.getAttribute("auth"); %>
<!doctype html>
<html class="fixed">
	<head>
		<!-- Basic -->
		<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="keywords" content="HTML5 Admin Template" />
		<meta name="description" content="Porto Admin - Responsive HTML5 Template">
		<meta name="author" content="okler.net">
		<!-- Mobile Metas -->
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<!-- Vendor CSS -->
		<link rel="stylesheet" href="../admin/css/bootstrap.css" />
		<link rel="stylesheet" href="../admin/css/font-awesome/css/font-awesome.css" />
        <link rel="stylesheet" href="../admin/css/select2.css" />
		<!-- Theme CSS -->
		<link rel="stylesheet" href="../admin/css/theme.css" />
		<!-- Skin CSS -->
		<link rel="stylesheet" href="../admin/css/default.css" />
		<!-- Theme Custom CSS -->
		<!-- Theme Custom ../admin/css -->
		<script src="../admin/js/modernizr.js"></script>
	</head>
	<body>
		<section role="main" class="content-body" style="margin-top: 50px;">
			<!-- start: page -->
			<section class="panel">
				<header class="panel-heading">
					<h2 class="panel-title">权限-详情</h2>
				</header>
				<div class="panel-body">
					<div class="panel-body">
						<p class="lead"> <span class="alternative-font"><%=auth.get("auth_name") %></span> </p>
						<p>
							<ul class="list-inline">
								<li>权限名称：<input name="auth_name" id="auth_name" value='<%=auth.get("auth_name") %>'/></li>
								<li>所属控制器：<input name="auth_c" id="auth_c" value='<%=auth.get("auth_c") %>'/></li>
								<li>所属方法名：<input name="auth_a" id="auth_a" value='<%=auth.get("auth_a") %>'/></li>
								<li>级别：<input name="level" id="level" value='<%=auth.get("level") %>'/></li>
							</ul>
							<p>所属菜单</p>
							<% List<MenuModel> list=(List)request.getAttribute("menus");
								for(int i=1;i<=list.size();i++){
									MenuModel menu = list.get(i-1);
							%>
								<p><input type="checkbox" name="menuid" value='<%=menu.get("id")%>'/><%=menu.get("menu_name")%></p>
			                <%} %>
						</p>
						<div class="mb-xs text-center">
							<a class="btn btn-facebook mb-md ml-xs mr-xs" onclick="editAuth()">确定提交 </a>
	                        <a class="btn btn-facebook mb-md ml-xs mr-xs" href="../admin/authView" >取消</a>
						</div>
					</div>
				</div>
			</section>
		</section>
<!-- Specific Page Vendor -->
<!-- Vendor -->
<script src="../admin/js/jquery.js"></script>
<script src="../admin/js/layer.js"></script>
<!-- Theme Base, Components and Settings -->
<script src="../admin/js/theme.js"></script>
<!-- Theme Custom -->
<script src="../admin/js/theme.custom.js"></script>
<!-- Theme Initialization Files -->
<script src="../admin/js/theme.init.js"></script>
<!-- Examples -->
<script src="../admin/js/tables/examples.datatables.default.js"></script>
<script src="../admin/js/tables/examples.datatables.row.with.details.js"></script>
<script src="../admin/js/tables/examples.datatables.tabletools.js"></script>
<script type="text/javascript">
window.onload = function (){
	var str = '${menuid}';
	$(str.split(",")).each(function (i,dom){
		
        $(":checkbox[value='"+dom+"']").prop("checked",true);
        $(":checkbox[id='"+dom+"']").prop("checked",true);
    });
} 

function editAuth(){
	var  id = ${id};
	var auth_name = $("#auth_name").val();
	var auth_c = $("#auth_c").val();
	var auth_a = $("#auth_a").val();
	var level = $("#level").val();
	var menuids = [];
	$('input[name="menuid"]:checked').each(function(){ 
		menuids.push($(this).val());
	}); 
	var url = '../admin/editAuth?id='+id+'&auth_name='+auth_name+'&auth_c='+auth_c+'&auth_a='+auth_a+'&level='+level+'&menuid='+menuids;
	$.get(url, function(data){
		if(data=='suc'){
			layer.msg('修改成功！');
			location.href='../admin/authView';
		}else{
			layer.msg('更新失败...', {icon: 5});
		}
	});
}
</script>
</body>

</html>